<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 删除按钮 -->
			<cl-multi-delete-btn />
			<cl-flex1 />
			<!-- 条件搜索 -->
			<cl-search ref="Search" />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" setup>
defineOptions({
	name: 'pay-config'
});

import { useCrud, useTable, useUpsert, useSearch } from '@cool-vue/crud';
import { useCool } from '/@/cool';
import { useI18n } from 'vue-i18n';
import { reactive } from 'vue';
const { service } = useCool();
const { t } = useI18n();

// 选项
const options = reactive({
	type: [
		{ label: t('微信支付'), value: 0, type: 'danger' },
		{ label: t('支付宝支付'), value: 1, type: 'success' }
	],
	status: [
		{ label: t('禁用'), value: 0, type: 'danger' },
		{ label: t('启用'), value: 1, type: 'success' }
	],
	baseStatusList: [
		{ label: t('禁用'), value: 0, type: 'danger' },
		{ label: t('启用'), value: 1, type: 'success' }
	]
});

// cl-upsert
const Upsert = useUpsert({
	items: [
		{
			label: t('支付方式名称'),
			prop: 'name',
			component: { name: 'el-input', props: { clearable: true } },
			span: 12,
			required: true
		},
		// {
		// 	label: t('支付类型'),
		// 	prop: 'type',
		// 	component: { name: 'el-radio-group', options: options.type },
		// 	value: 0,
		// 	required: true
		// },
		{
			label: t('输入AppId'),
			prop: 'appId',
			component: { name: 'el-input', props: { clearable: true } },
			span: 12
		},
		{
			label: t('输入商户号'),
			prop: 'mchId',
			component: { name: 'el-input', props: { clearable: true } },
			span: 12
		},
		{
			label: t('apiclient_key路径'),
			prop: 'apiclient_key',
			component: { name: 'el-input', props: { clearable: true } },
			span: 12
		},
		{
			label: t('apiclient_cert路径'),
			prop: 'apiclient_cert',
			component: { name: 'el-input', props: { clearable: true } },
			span: 12
		},
		{
			label: t('回调地址'),
			prop: 'notifyUrl',
			component: { name: 'el-input', props: { clearable: true } },
			span: 12
		},
		{
			label: t('启用状态'),
			prop: 'status',
			component: { name: 'el-radio-group', options: options.status },
			value: 1,
			required: true
		},
		{
			label: t('是否默认'),
			prop: 'baseStatus',
			component: { name: 'el-radio-group', options: options.baseStatusList },
			value: 1,
			required: true,
		},
		{
			label: t('排序号'),
			prop: 'orderNum',
			hook: 'number',
			component: { name: 'el-input-number', props: { min: 0 } },
			span: 12,
			required: true
		},
		{
			label: t('备注信息'),
			prop: 'remark',
			component: {
				name: 'el-input',
				props: { type: 'textarea', rows: 4 }
			}
		}
	]
});

// cl-table
const Table = useTable({
	columns: [
		{ type: 'selection' },
		{ label: t('支付方式名称'), prop: 'name', minWidth: 140 },
		{
			label: t('支付类型'),
			prop: 'type',
			minWidth: 120,
			dict: options.type
		},
		{ label: t('商户号'), prop: 'mchId', minWidth: 140 },
		{ label: t('回调地址'), prop: 'notifyUrl', minWidth: 140 },
		{
			label: t('启用状态'),
			prop: 'status',
			minWidth: 100,
			component: { name: 'cl-switch' },
			dict: options.status
		},
		{
			label: t('是否默认'),
			prop: 'baseStatus',
			minWidth: 100,
			component: { name: 'cl-switch' },
			dict: options.baseStatusList
		},
		{
			label: t('备注信息'),
			prop: 'remark',
			showOverflowTooltip: true,
			minWidth: 200
		},
		{
			label: t('创建时间'),
			prop: 'createTime',
			minWidth: 170,
			sortable: 'desc',
			component: { name: 'cl-date-text' }
		},
		{
			label: t('更新时间'),
			prop: 'updateTime',
			minWidth: 170,
			sortable: 'custom',
			component: { name: 'cl-date-text' }
		},
		{ type: 'op', buttons: ['edit', 'delete'] }
	]
});

// cl-search
const Search = useSearch();

// cl-crud
const Crud = useCrud(
	{
		service: service.pay.config
	},
	app => {
		app.refresh();
	}
);

// 刷新
function refresh(params?: any) {
	Crud.value?.refresh(params);
}
</script>
